user
04/25/2021, 9:37 PMCypress.Commands.add('login', (email, password, overrides = {}) => {
Cypress.log({
name: 'loginViaAuth0',
});
const options = {
method: 'POST',
url: Cypress.env('auth_url'),
body: {
grant_type: 'password',
username: email,
password: password,
audience: Cypress.env('auth_audience'),
scope: 'openid profile email',
client_id: Cypress.env('auth_client_id'),
client_secret: Cypress.env('auth_client_secret'),
},
};
cy.request(options)
.then((resp) => {
return resp.body;
})
.then((body) => {
const { access_token, id_token } = body;
const auth0State = {
nonce: '',
state: id_token
};
cy.visit(`/callback?code=${auth0State.state}state=${access_token}`,{
onBeforeLoad(win) {
win.document.cookie = 'auth0.is.authenticated', 'true';
win.document.cookie = '_legacy_auth0.is.authenticated', 'true';
}
}).as('login');
})
cy.wait('@login'. {timeout: 60000});
});